<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>游戏商城-管理后台</title>
    <link rel="shortcut icon" href="${ bp }/static/image/icon.png" type="image/x-icon">
    <link rel="stylesheet" href="${ bp }/static/layui/css/layui.css">
    <style type="text/css">
        .layui-body {
            overflow: hidden;
        }

        #playshop-tab {
            margin: 0;
        }

        /* 首页标签禁止关闭 */
        [lay-id="首页"] i {
            display: none !important;
        }

        .layui-layout-middle {
            display: block;
            height: 60px;
            width: 60px;
            float: left;
            position: absolute;
            top: 0;
            left: 200px;
        }

        .layui-layout-middle a {
            display: block;
            line-height: 60px;
            text-align: center;
            color: #d0e5f2;
        }
    </style>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">游戏商城-管理后台</div>

        <div class="layui-layout-middle">
            <a href="${bp}/list?method=list&pageNum=1&pageSize=7&price=0">游戏商城</a>
        </div>

        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="${ bp }/static/image/user.jpg" class="layui-nav-img">
                    ${
                            onlineAdmin.nickname
                            }
                </a>
                <dl class="layui-nav-child">
                    <dd class="playshop-nav-item"><a href="${ bp }/admin/info.jsp">个人资料</a></dd>
                    <dd class="playshop-nav-item"><a href="${ bp }/admin/modify.jsp">修改密码</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="${ bp }/admin/login.jsp">退出平台</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="playshop-nav">
                <li class="layui-nav-item playshop-nav-item playshop-nav-item-default-active"><a
                        href="${ bp }/user/main.jsp">首页</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">用户管理</a>
                    <dl class="layui-nav-child">
                        <dd class="playshop-nav-item"><a href="${ bp }/user/list.jsp">用户数据</a></dd>
                        <dd class="playshop-nav-item"><a href="${ bp }/user/createTimeStat.jsp">注册统计</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">游戏管理</a>
                    <dl class="layui-nav-child">
                        <dd class="playshop-nav-item"><a href="${ bp }/game/list.jsp">游戏数据</a></dd>
                        <dd class="playshop-nav-item"><a href="${ bp }/game/createTimeStat.jsp">游戏发布统计</a></dd>
                        <dd class="playshop-nav-item"><a href="${ bp }/keyword/list.jsp">秘钥管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item playshop-nav-item playshop-nav-item-default"><a
                        href="${ bp }/comment/list.jsp">评论管理</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 选项卡 -->
        <div id="playshop-tab" class="layui-tab layui-tab-card" lay-filter="playshop-tab" lay-allowclose="true">
            <!-- 选项卡标题部分 -->
            <ul class="layui-tab-title">
            </ul>
            <!-- 选项卡内容部分 -->
            <div class="layui-tab-content">
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © Brysj - 版权所有
    </div>
</div>

<!-- layui.all.js 包含layui核心库和所有组件 -->
<script src="${ bp }/static/layui/layui.all.js"></script>
<script>
    // Layui遵循模块化开发思想，所有的功能模块，原则上在使用之前都需要声明
    layui.use(['element', 'jquery'], function () {
        let element = layui.element;
        let $ = layui.jquery;

        // 点击菜单栏目切换iframe内容
        $('.playshop-nav-item a').click(function (e) {
            // 禁止a标签跳转
            e.preventDefault();
            // 获取a标签的href属性
            let href = this.href;
            // 获取标题
            let title = this.innerText;

            // 判断是否已经存在该标签
            if ($('#playshop-tab ul li[lay-id="' + title + '"]').length === 0) {
                // 不存在，则添加选项卡
                element.tabAdd('playshop-tab', {
                    title: title,
                    content: '<iframe id="' + title + '" src="' + href + '" width="100%" height="1000px" frameborder="0" onload="this.height = document.documentElement.clientHeight - 160"></iframe>',
                    id: title
                })
            } else {
                // 存在，则刷新页面
                // 获取iframe中的window，然后只重载iframe中的页面
                document.getElementById(title).contentWindow.location.reload(true);
            }

            // 切换选项卡
            element.tabChange('playshop-tab', title);
        })

        // 切换选项卡，菜单自动切换
        element.on('tab(playshop-tab)', function (data) {
            // 获取选项卡id
            let id = $(this).attr('lay-id');
            // 移出现有的.layui-this
            $('.playshop-nav-item.layui-this').removeClass('layui-this');
            // 找到和选项卡id相同的菜单
            $('.playshop-nav-item').each((index, item) => {
                if ($(item).text() === id) {
                    $(item).addClass('layui-this');
                }
            })
        });

        // 默认打开首页
        $('.playshop-nav-item-default-active a').trigger('click');

    });
</script>

</body>
</html>
